<template>
	<uv-popup
		ref="recycleAddressPopup"
		mode="bottom"
		bgColor="transparent"
		:closeOnClickOverlay="true"
		:safeAreaInsetBottom="false"
	>
		<view class="recycle-address-content">
			<hsb-common-popup-header
				title="请选择您的地址"
				@close="close"
			/>
			<view class="recycle-address-body">
				<scroll-view
					scroll-y="true"
					class="recycle-address-scroll-view"
				>
					<view class="all-recycle-address">
						<view class="valid-address-list">
							<hsb-business-address-list
								:list="validList"
								@choose="choose"
								@edit="edit"
							/>
						</view>
						<view class="disabled-address-list">
							<view
								v-if="isVisit && disabledList.length"
								class="disabled-tips"
							>
								超出上门范围，可选择邮寄
							</view>
							<hsb-business-address-list
								:list="disabledList"
								@choose="choose"
								@edit="edit"
							/>
						</view>
					</view>
				</scroll-view>
				<view class="recycle-address-add">
					<view
						class="recycle-address-btn"
						@click="edit"
					>
						<text>新增地址</text>
					</view>
				</view>
			</view>
		</view>
	</uv-popup>
</template>

<script>
export default {
	props: {
		list: Array,
		selectRecycle: Object
	},
	computed: {
		isVisit () {
			return ['3', '4'].includes(this.selectRecycle.recycleWay)
		},
		validList () {
			return this.list.filter(e => e.status === '1' && e.latitude && e.longitude)
		},
		disabledList () {
			return this.list.filter(e => e.status !== '1' || !e.latitude || !e.longitude)
		}
	},
	methods: {
		open () {
			this.$refs.recycleAddressPopup.open()
		},
		close () {
			this.$refs.recycleAddressPopup.close()
		},
		choose (addrInfo) {
			if (addrInfo.status !== '1' || !addrInfo.latitude || !addrInfo.longitude) return
			this.$emit('choose', addrInfo)
			this.close()
		},
		edit (addrInfo = {}) {
			if (addrInfo.addrId) {
				this.$emit('edit', addrInfo)
			} else {
				this.$emit('add', {})
			}
			this.close()
		}
	}
}	
</script>

<style lang="scss" scoped>
@import './index.scss';
</style>